package com.tom.demo.controller.approvalsettings;

import com.tom.demo.common.annotation.OperaLog;
import com.tom.demo.common.entity.OaProcessType;
import com.tom.demo.common.enumeration.OperaTypeEnum;
import com.tom.demo.common.response.Result;
import com.tom.demo.service.approvalsettings.OaProcessTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = {"审批类型"})
@RestController
@RequestMapping("/oaProcessType")
public class OaProcessTypeController {

    @Resource
    private OaProcessTypeService oaProcessTypeService;

    @PostMapping(path = {"/list"})
    @ApiOperation(value = "获取模板类型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", defaultValue = "1", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页查询多少条", defaultValue = "10", dataType = "int", paramType = "query")
    })
    public Result list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                       @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                       @RequestBody OaProcessType oaProcessType) {
        return oaProcessTypeService.list(page,pageSize,oaProcessType);
    }

    @PostMapping(path = {"/insert"})
    @ApiOperation(value = "新增模板类型")
    @OperaLog(operaModel = "审批类型",operaType = OperaTypeEnum.ADD,operaDesc = "新增模板类型")
    public Result insert(@RequestBody OaProcessType oaProcessType) {
        return oaProcessTypeService.insert(oaProcessType);
    }

    @PutMapping(path = {"/updateById"})
    @ApiOperation(value = "修改模板类型")
    @OperaLog(operaModel = "审批类型",operaType = OperaTypeEnum.UPDATE,operaDesc = "修改模板类型")
    public Result updateById(@RequestBody OaProcessType oaProcessType) {
        return oaProcessTypeService.updateById(oaProcessType);
    }

    @DeleteMapping(path = {"/deleteById/{id}"})
    @ApiOperation(value = "删除模板类型")
    @OperaLog(operaModel = "审批类型",operaType = OperaTypeEnum.DELETE,operaDesc = "删除模板类型")
    public Result deleteById(@PathVariable(value = "id")String id) {
        return oaProcessTypeService.deleteById(id);
    }

    @GetMapping(path = {"/getOptions"})
    @ApiOperation(value = "获取审批类型下拉选项")
    public Result getOptions() {
        return oaProcessTypeService.getOptions();
    }

}
